package com.edward.action;


import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import org.springframework.security.annotation.Secured;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import com.edward.JsonDateProcessor;
import com.edward.PagerModel;
import com.edward.model.CncaList;
import com.edward.service.CncaListManager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class CncaListAction extends ActionSupport {


	private static final long serialVersionUID = -4852643111361308365L;

	private CncaListManager cncaListManager;
	
	private CncaList cncaList;
	
	private int limit;
	
	private int start;
	

	public CncaList getCncaList() {
		return cncaList;
	}

	public void setCncaList(CncaList cncaList) {
		this.cncaList = cncaList;
	}

	public void setCncaListManager(CncaListManager cncaListManager) {
		this.cncaListManager = cncaListManager;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}



	@Secured("ROLE_REPORT_ADD")
	public String add() throws Exception{
		ActionContext ctx = ActionContext.getContext();        
		  HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);    
		response.setContentType("text/html;charset=UTF-8");
		cncaListManager.addCncaList(cncaList);
		 response.getWriter().print("{success:true,msg:'添加成功'}");
		return null;
	}
	
	
	@Secured("ROLE_REPORT_UPDATE")
	public String update() throws Exception {

		ActionContext ctx = ActionContext.getContext();        
		  HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);    
		response.setContentType("text/html;charset=UTF-8");
		cncaListManager.updateCncaList(cncaList);
		response.getWriter().print("{success : true , msg : '修改成功!'}");
		return null;
	}
	
	@Secured("ROLE_REPORT_UPDATE")
	public String delete() throws Exception {

		ActionContext ctx = ActionContext.getContext();        
		  HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);    
		response.setContentType("text/html;charset=UTF-8");
		cncaListManager.deleteCncaList(cncaList.getId());
		response.getWriter().print("{success : true , msg : '删除成功!'}");
		return null;
	}
	
	@Secured("ROLE_REPORT")
	public String get() throws Exception {

		ActionContext ctx = ActionContext.getContext();        
		HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);    
		response.setContentType("text/html;charset=UTF-8");
	    JsonConfig cfg = new JsonConfig();
		cfg.registerJsonValueProcessor(java.util.Date.class, new JsonDateProcessor());
		cfg.registerJsonValueProcessor(java.sql.Date.class, new JsonDateProcessor());
		PagerModel pager;
		pager = cncaListManager.pagerList(start, limit);
		JSONObject jsonObject = JSONObject.fromObject(pager,cfg);
		String jsonStr = jsonObject.toString();
		response.getWriter().print(jsonStr);
		 
	           
		return null;
	}
	
	@Secured("ROLE_REPORT")
	 public String getListJudge() throws Exception {
			ActionContext ctx = ActionContext.getContext();        
			HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);    
			response.setContentType("text/html;charset=UTF-8");
				response.getWriter().print("{success : true , msg : '成功!',deny:false}");
		 return null;
	 }

	
	
	
	
}
